package net.tngou.iask.service;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import net.tngou.iask.dao.AnalysisDao;
import net.tngou.iask.jdbc.OrderType;
import net.tngou.iask.jdbc.PageUtil;
import net.tngou.iask.jdbc.QueryHelper;
import net.tngou.iask.pojo.Analysis;
import net.tngou.iask.pojo.Cure;
import net.tngou.iask.pojo.Health;
import net.tngou.iask.pojo.POJO;
import net.tngou.iask.pojo.Patient;
import net.tngou.iask.pojo.Question;

/**
  * 分析
  * @author tngou@tngou.net
  *
  */
public class AnalysisService extends BaseService {
	/**
	 * 取得患者
	 * @param analysis
	 * @param page
	 * @param size
	 * @param keyword
	 * @return
	 */
	public PageUtil	getPatient(long analysis,int page,int size,String keyword) {
		AnalysisDao dao = new AnalysisDao();
		return dao.getPatient(analysis, page, size, keyword);
	}
	
	public List<Map<String, Object>> getPatient(long analysis) {
		AnalysisDao dao = new AnalysisDao();
		return dao.getPatient(analysis);
	}
	
	/**
	 * 取得需要统计的目录
	 * @param analysis
	 * @return
	 */
	public List<Question>	getQuestion(long analysis) {	
		AnalysisDao dao = new AnalysisDao();
		return dao.getQuestion(analysis);
	}
	
	/**
	 * 
	 * @param list
	 * @return
	 */
	public List<Health> getHeath(List<Map<String, Object>> list) {
		List<Long> ids = new ArrayList<>();
		list.forEach(e->{ids.add(Long.parseLong(e.get("id").toString()));});
		AnalysisDao dao = new AnalysisDao();
		return dao.getHeath(ids.toArray());
	}
	
	
	/**
	 * 添加自定义分析用户
	 * @param analysis
	 * @param patient
	 * @return
	 */
	public boolean savePatient(long analysis,long patient) {
		List<Cure> list = (List<Cure>) getList(1, 1, "id", OrderType.ASC, new Cure());
		Date bdate=null;
		if(list!=null&&!list.isEmpty())
		{
			bdate=list.get(0).getTdate();
		}else
		{
			Patient p=new Patient().get(patient);
			if(p==null)return false;
			bdate=new Date(p.getTime().getTime());
		}
		AnalysisDao dao = new AnalysisDao();
		return dao.savePatient(analysis, patient,bdate);
	}
	/**
	 * 删除自定义分析用户
	 * @param analysis
	 * @param patient
	 * @return
	 */
	public boolean deletePatient(long analysis,long patient) {
		AnalysisDao dao = new AnalysisDao();
		return dao.deletePatient(analysis, patient);
	}
	
	/**
	 * 添加自定义栏目
	 * @param analysis
	 * @param question
	 * @return
	 */
	public boolean saveQuestion(long analysis,long question) {
		AnalysisDao dao = new AnalysisDao();
		return dao.saveQuestion(analysis, question);
	}
	
	/**
	 * 删除自定义栏目
	 * @param analysis
	 * @param question
	 * @return
	 */
	public boolean deleteQuestion(long analysis,long question) {
		AnalysisDao dao = new AnalysisDao();
		return dao.deleteQuestion(analysis, question);
	}
	/**
	 * 删除自定义分析
	 * @param analysis
	 */
	public boolean delete(Analysis analysis){
		AnalysisDao dao = new AnalysisDao();
		dao.delete(analysis.getId());
		return analysis.delete();
	}
	
	/**
	 * 取得没有入组的用户
	 * @param page
	 * @param size
	 * @param main
	 * @param analysis
	 * @param keyword
	 * @return
	 */
	public PageUtil getCurePage(int page,int size,long main,long analysis,String keyword) {
		AnalysisDao dao = new AnalysisDao();
		return dao.getCurePage(page, size, main, analysis, keyword);
	}

	/**
	 * 取得没有选择的问题
	 * @param page
	 * @param size
	 * @param main
	 * @param analysis
	 * @param keyword
	 * @return
	 */
	public PageUtil getQuestionPage(int page,int size,long main,long analysis,String keyword) {
		AnalysisDao dao = new AnalysisDao();
		return dao.getQuestionPage(page, size, main, analysis, keyword);
	}

	
}
